package com.adcc.eoss.cawebservice.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.adcc.eoss.cawebservice.service.FlightPlanService;
import com.adcc.eoss.cawebservice.service.PilotService;
import com.adcc.eoss.cawebservice.service.UserService;

@RestController
public class UserController {

	protected final Logger log = LoggerFactory.getLogger(getClass());

	@Autowired
	private UserService userService;

	@Autowired
	private PilotService pilotService;

	@Autowired
	private FlightPlanService flightPlanService;

	@RequestMapping("/test")
	public String test() {
		log.info("Test");
		return "OK";
	}

	@RequestMapping("/user")
	public int getUser() {
		log.info("Get user");
		return userService.QueryForCount();
	}

	/**
	 * @param id
	 *            人员编号
	 * @param own
	 *            人员所属
	 * @param id_card
	 *            身份证号
	 * @return
	 */
	@RequestMapping(value = "/getpilot", produces = MediaType.APPLICATION_JSON_VALUE,method = RequestMethod.POST)
	public String getPilot(String id_card) {
		log.info("-----------" + id_card + "-----------");
		return pilotService.getPilot(id_card);
	}

	/**
	 * @param pilotId 飞行员工号
	 * @param own 分公司所属
	 * @param std 计飞
	 * @param sta 计达
	 * @param dep 起飞场
	 * @param arr 落地场
	 * @param flt 航班号
	 * @param fdt 计划日期
	 * @param long_reg 短机型
	 * @param beginDate 开始时间
	 * @param endDate 结束时间
	 * @param arn 机尾号
	 * @return
	 */
	@RequestMapping(value = "/crewschedule", produces = MediaType.APPLICATION_JSON_VALUE)
	public String getFlightPlan(String pilotId, String own, String std, String sta, String dep, String arr, String flt, String fdt,
			String short_reg, String beginDate, String endDate, String arn) {
		log.info("-----------crewschedule-----------");
		return flightPlanService
				.getFlightPlan(pilotId, own, std, sta, dep, arr, flt, fdt, short_reg, beginDate, endDate, arn);
	}
	
	@RequestMapping(value = "/getpilotByName", produces = MediaType.APPLICATION_JSON_VALUE,method = RequestMethod.POST)
	public String getPilotByName(String name) {
		log.info("-----------" + name + "-----------");
		return pilotService.getPilotByName(name);
	}
	
	/**
	 * 
	 * @param flt 航班号
	 * @param fdt 格式：2015-04-01
	 * @return
	 */
	@RequestMapping(value = "/getFlightInfo", produces = MediaType.APPLICATION_JSON_VALUE,method = RequestMethod.POST)
	public String getFlightInfo(String flt,String fdt) {
		log.info("-----------" + flt + "-----------");
		return flightPlanService.getFlightInfo(flt,fdt);
	}

}